<template>
  <div>
    <el-form ref="dataForm" :model="formdata" label-position="left" label-width="90px" class="ml50" :inline="true" size="medium">
      <el-row>
        <el-col :span="10">
          <el-form-item label="所属社区" prop="type">
            <el-select v-model="formdata.org_id" class="filter-item" placeholder="请选择" @change="org_change">
              <el-option label="请选择" value="0" />
              <el-option v-for="item in org_listOptions" :key="item.id" :label="item.organ_name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="所属网格" prop="type">
            <el-select v-model="formdata.grid_id" class="filter-item" placeholder="请选择">
              <el-option label="请选择" value="0" />
              <el-option v-for="item in grid_listOptions" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10">
          <el-form-item label="建设时间" prop="timestamp">
            <el-date-picker v-model="formdata.build_time" type="datetime" placeholder="请选择日期" />
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="小区名称" prop="title">
            <el-input v-model="formdata.name" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10">
          <el-form-item label="小区物业" prop="title">
            <el-input v-model="formdata.property" />
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="小区地址" prop="title">
            <el-input v-model="formdata.address" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10">
          <el-form-item label="小区联系人" prop="title">
            <el-input v-model="formdata.contacts" />
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="联系电话" prop="number">
            <el-input v-model="formdata.tel" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="小区介绍">
          <el-input v-model="formdata.intro" style="width: 200%;" :autosize="{ minRows: 4, maxRows: 6}" type="textarea" placeholder="请填写" />
        </el-form-item>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogClose">
        取消
      </el-button>
      <el-button type="primary" @click="projectedit()">
        保存
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Edit',
  props: { // 接受父组件传过来参数值的子组件参数
    detailId: {
      type: Number
    },
    // dialog: {
    //   type: Boolean,
    //   default() {
    //     return false
    //   }
    // },
    title: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {
      org_listOptions: [],
      grid_listOptions: [],
      formdata: {}
    }
  },
  computed: {

  },
  created() {
    // console.log('created')
    this.get_org_list()
  },
  mounted() {
    // console.log('mounted')
  },
  methods: {
    dialogClose() {
      this.$emit('dialogClose', false)
    },
    get_org_list() {
      this.$api.comm.getorg_list().then(response => {
        // console.log('response', response)
        this.org_listOptions = response.data
        this.loadData()
      })
    },
    org_change(value) {
      console.log('value', value)
      this.formdata.grid_id = '请选择'
      /* 为网格列表取值*/
      for (const item of this.org_listOptions) {
        if (item.id === value) {
          // console.log('item', item)
          this.grid_listOptions = item.grid_list
        }
      }
    },
    loadData() {
      this.$api.project.projectview({
        id: this.detailId
      }).then(response => {
        this.formdata = response.data
        for (const item of this.org_listOptions) {
          if (item.id === this.formdata.org_id) {
            // console.log('item', item)
            this.grid_listOptions = item.grid_list
          }
        }
      })
    },
    projectedit() {
      this.$api.project.projectedit(this.formdata).then(response => {})
    }
  }
}
</script>
